﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inspired.Euler
{
    public static class Problem033
    {
        /// <summary>
        /// Discover all the fractions with an unorthodox cancelling method.
        /// </summary>
        [EulerProblem(33, Title = "Discover all the fractions with an unorthodox cancelling method.")]
        public static long Solve()
        {
            List<double> results = new List<double>();
            for (long numerator = 10; numerator <= 99; numerator++)
            {
                for (long denominator = numerator + 1; denominator <= 99; denominator++)
                {
                    if (numerator % 10 == 0 && denominator % 10 == 0)
                        continue;

                    for(int number =1; number <= 9; number++)
                    {
                        if(numerator.AsEnumerable().Contains(number) && denominator.AsEnumerable().Contains(number))
                        {
                            long n1 = numerator.AsEnumerable().Where(n => n != number).ToInt64();
                            long d1 = denominator.AsEnumerable().Where(n => n != number).ToInt64();
                            if (d1 == 0)
                                continue;

                            double result = (double)n1 / (double)d1;
                            if (((double)numerator / (double)denominator) == result)
                            {
                                results.Add(result);
                                Console.WriteLine("{0}/{1} == {2:00}/{3:00} == {4:0.000000}", numerator, denominator, n1, d1, result);
                            }
                        }
                    }
                }
            }
            return (long)(results[0] * results[1] * results[2] * results[3] * 10000);
        }
    }
}
